package com.ls.hnks.advice;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotRoleException;
import com.ls.hnks.util.Result;
import com.ls.hnks.util.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Order(10085)
@Slf4j
public class SaTokenExceptionHandler {
    // 鉴权异常拦截
    @ExceptionHandler(NotRoleException.class)
    public Result handlerNotRoleException(NotRoleException e) {
        log.info("角色检验不通过，用户角色中" + e.getMessage());
        return Result.error(ResultCodeEnum.FORBIDDEN);
    }

    @ExceptionHandler(NotLoginException.class)
    public Result handlerNotLoginException(NotLoginException e) {
        log.info(e.getMessage());
        return Result.error(ResultCodeEnum.INVALID_TOKEN);
    }
}
